import requests
import os
import threading

from missav.get_m3u8 import get_headers
headers = get_headers()
class Downloader(threading.Thread):
    def __init__(self, url, ts_url, file_path):
        threading.Thread.__init__(self)
        self.url = url
        self.ts_url = ts_url
        self.file_path = file_path

    def run(self):
        r = requests.get(self.ts_url,headers=headers, verify=False)
        print(self.url)
        if r.status_code == 200:
            with open(self.file_path, 'ab') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)
